package com.ycl.util;

import javax.servlet.http.HttpServletResponse;
import java.io.*;

/**
 * @ClassName: FileUtil
 * @Package: Image_synthesis
 * @Description:
 * @Author: sen.yang@youhualin.com
 * @Date: 2021/12/22 14:18
 * @Copyright: 德慧信息技术有限公司
 */
public class FileUtil {

    public static void download(String path, HttpServletResponse res){
        // 发送给客户端的数据
        OutputStream outputStream = null;
        try (// 读取filename
             BufferedInputStream bis = new BufferedInputStream(new FileInputStream(path))){
            outputStream = res.getOutputStream();
            byte[] buff = new byte[1024];

            int i = bis.read(buff);
            while (i != -1) {
                outputStream.write(buff, 0, buff.length);
                outputStream.flush();
                i = bis.read(buff);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
